/**
 * 
 */
package com.netjava.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.netjava.task.MyTask;

/**
 * @author Administrator
 *
 */
public class TaskListener implements ServletContextListener {

	/* (non-Javadoc)
	 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
	 */
	private   java.util.Timer   timer   =   null;    
	public void contextDestroyed(ServletContextEvent event) {
		  timer.cancel();    
          event.getServletContext().log("定时器销毁");    


	}

	/* (non-Javadoc)
	 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
	 */
	public void contextInitialized(ServletContextEvent event) {  
		
		timer   =   new   java.util.Timer(true);    
	    event.getServletContext().log("定时器已启动");                    
		timer.schedule(new  MyTask(event.getServletContext()),   0,   1000);    
	    event.getServletContext().log("已经添加任务调度表");    
 
             

	}

}
